package com.suyuan.service.impl;

import com.suyuan.dao.CompanyInfoMapper;
import com.suyuan.dao.ProPicMapper;
import com.suyuan.entity.CompanyInfo;
import com.suyuan.entity.CompanyInfoExample;
import com.suyuan.service.CompanyService;
import com.suyuan.vo.CompanyVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("companyService")
public class CompanyServiceImpl implements CompanyService {
    @Resource
    private CompanyInfoMapper companyInfoMapper;
    @Resource
    private ProPicMapper proPicMapper;

    public CompanyInfo companyDetail(Integer id) {
        return companyInfoMapper.selectByPrimaryKey(id);
    }

    public List<CompanyInfo> findAll() {
        List<CompanyInfo> vos = new ArrayList<CompanyInfo>();
        List<CompanyInfo> companys = companyInfoMapper.selectByExample(new CompanyInfoExample());
       return companys;
    }

    public List<CompanyVO> findALLInfo() {
        List<CompanyVO> vos = new ArrayList<CompanyVO>();
        List<CompanyInfo> companys = companyInfoMapper.selectByExample(new CompanyInfoExample());
        for(CompanyInfo company : companys){
            Integer gid = company.getGid();
            String image = proPicMapper.findCompanyPic(gid);
            CompanyVO vo = new CompanyVO();
            vo.setImage(image);
            vo.setCompany(company);
            vos.add(vo);
        }
        return vos;
    }

    /**
     * 查找所有养殖公司
     * @return
     */
    public List<CompanyInfo> findAllFeedCompany(Integer typeID) {
        CompanyInfoExample companyInfoExample = new CompanyInfoExample();
        CompanyInfoExample.Criteria criteria =  companyInfoExample.createCriteria();
        criteria.andComptypeidEqualTo(typeID);
        return companyInfoMapper.selectByExample(companyInfoExample);
    }

    public List<CompanyInfo> findByCategory(Integer typeId) {
        CompanyInfoExample companyInfoExample = new CompanyInfoExample();
        CompanyInfoExample.Criteria criteria =  companyInfoExample.createCriteria();
        criteria.andComptypeidEqualTo(typeId);
        return companyInfoMapper.selectByExample(companyInfoExample);
    }


}
